package com.ga.api.controller.product;

import com.ga.api.service.product.InsuranceCompanyService;
import com.ga.common.annotation.DataChangeLog;
import com.ga.common.annotation.RequirePermission;
import com.ga.common.model.ApiResponse;
import com.ga.core.vo.product.InsuranceCompanyVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "보험사 관리")
@RestController
@RequestMapping("/api/companies")
@RequiredArgsConstructor
public class CompanyController {

    private final InsuranceCompanyService companyService;

    @GetMapping
    @RequirePermission(menu = "COMPANY", perm = "READ")
    public ApiResponse<List<InsuranceCompanyVO>> list(@RequestParam(required = false, defaultValue = "false") boolean activeOnly) {
        return ApiResponse.ok(companyService.list(activeOnly));
    }

    @GetMapping("/{companyId}")
    @RequirePermission(menu = "COMPANY", perm = "READ")
    public ApiResponse<InsuranceCompanyVO> detail(@PathVariable Long companyId) {
        return ApiResponse.ok(companyService.detail(companyId));
    }

    @PostMapping
    @RequirePermission(menu = "COMPANY", perm = "CREATE")
    @DataChangeLog(menu = "COMPANY", table = "insurance_company")
    public ApiResponse<Long> create(@RequestBody InsuranceCompanyVO vo) {
        return ApiResponse.ok(companyService.create(vo));
    }

    @PutMapping("/{companyId}")
    @RequirePermission(menu = "COMPANY", perm = "UPDATE")
    @DataChangeLog(menu = "COMPANY", table = "insurance_company")
    public ApiResponse<Void> update(@PathVariable Long companyId, @RequestBody InsuranceCompanyVO vo) {
        companyService.update(companyId, vo);
        return ApiResponse.ok();
    }
}
