package com.ningdatech.carapi.open.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.web.bind.annotation.*;

import com.ningdatech.carapi.company.entity.dto.ResCompanyArchivesDetailsDTO;
import com.ningdatech.carapi.company.entity.vo.CompanyEmployeesVO;
import com.ningdatech.carapi.company.service.ICompanyArchivesService;
import com.ningdatech.carapi.open.model.vo.CompanySecurityInfoVO;
import com.ningdatech.carapi.sys.entity.Company;
import com.ningdatech.carapi.sys.entity.dto.CompanySaveDTO;
import com.ningdatech.carapi.sys.entity.vo.CompanyVO;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

/**
 * @description: 企业档案管理
 * @author: liushuai
 * @date: 2022/10/25 17:58
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/open/api/v1/company-archives")
public class OpenApiCompanyArchivesController {
    private final ICompanyArchivesService iCompanyArchivesService;

    @GetMapping("/detail")
    public ResCompanyArchivesDetailsDTO getCompanyDetail(@RequestParam(value = "companyId", required = false) Long companyId) {
        return iCompanyArchivesService.getCompanyDetail(companyId);
    }

    @GetMapping("/employees")
    public List<CompanyEmployeesVO> getCompanyEmployees(@RequestParam(value = "companyId", required = false) Long companyId) {
        return iCompanyArchivesService.getCompanyEmployees(companyId);
    }

    /**
     * 企业安全信息
     * @param companyId
     * @return
     */
    @GetMapping("/security")
    public CompanySecurityInfoVO getCompanySecurityInfo(@RequestParam(value = "companyId", required = false) Long companyId) {
        return iCompanyArchivesService.getCompanySecurityInfo(companyId);
    }

    @ApiOperation(value = "二维码注册新企业", notes = "二维码注册新企业")
    @PostMapping("/register")
    public CompanyVO registerCompany(@Valid @RequestBody CompanySaveDTO data) {
        Company company =  iCompanyArchivesService.saveCompany(data);
        return BeanUtil.toBean(company, CompanyVO.class);
    }
}
