package com.usky.sas.controller.web;

import com.usky.common.core.bean.ApiResult;
import com.usky.sas.domain.SasSystemActivation;
import com.usky.sas.service.SasSystemActivationService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统激活接口
 *
 * 对应 API 文档：POST /prod-api/service-sas/activate
 */
@RestController
@RequestMapping
public class SasActivationController {

    @Autowired
    private SasSystemActivationService activationService;

    @PostMapping("/activate")
    public ApiResult<ActivationResponse> activate(@RequestBody ActivationRequest request) {
        SasSystemActivation activation = activationService.activate(request.getLicenseKey());
        ActivationResponse resp = new ActivationResponse();
        resp.setIsPerpetual(Boolean.TRUE.equals(activation.getIsPerpetual()));
        resp.setValidityTime(activation.getValidityTime());
        return ApiResult.success(resp);
    }

    @Data
    public static class ActivationRequest {
        private String licenseKey;
    }

    @Data
    public static class ActivationResponse {
        private Boolean isPerpetual;
        private java.time.LocalDateTime validityTime;
    }
}

