package cn.stylefeng.team.project.modular.filing.controller;

import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.team.project.modular.filing.pojo.businessExcel.add.BusinessExcelAddRequest;
import cn.stylefeng.team.project.modular.filing.pojo.businessExcel.del.BusinessExcelBatchDelRequest;
import cn.stylefeng.team.project.modular.filing.pojo.businessExcel.del.BusinessExcelDelRequest;
import cn.stylefeng.team.project.modular.filing.pojo.businessExcel.edit.BusinessExcelEditRequest;
import cn.stylefeng.team.project.modular.filing.pojo.businessExcel.edit.BusinessExcelUpdateStatusRequest;
import cn.stylefeng.team.project.modular.filing.pojo.businessExcel.edit.ExcelContentUpdateRequest;
import cn.stylefeng.team.project.modular.filing.pojo.businessExcel.query.BusinessExcelDetailRequest;
import cn.stylefeng.team.project.modular.filing.pojo.businessExcel.query.BusinessExcelListRequest;
import cn.stylefeng.team.project.modular.filing.pojo.businessExcel.response.BusinessExcelDetailResponse;
import cn.stylefeng.team.project.modular.filing.pojo.businessExcel.response.BusinessExcelListResponse;
import cn.stylefeng.team.project.modular.filing.service.BusinessExcelService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@ApiResource(name = "业务关联Excel")
public class BusinessExcelController {

    @Resource
    private BusinessExcelService businessExcelService;

    @PostResource(name = "添加业务关联Excel", path = "/businessExcel/add")
    public ResponseData<Long> add(@RequestBody @Validated BusinessExcelAddRequest businessExcelAddRequest) {
        Long primaryKeyId = businessExcelService.add(businessExcelAddRequest);
        return new SuccessResponseData<>(primaryKeyId);
    }

    @PostResource(name = "删除业务关联Excel", path = "/businessExcel/delete")
    public ResponseData<?> delete(@RequestBody @Validated BusinessExcelDelRequest businessExcelDelRequest) {
        businessExcelService.del(businessExcelDelRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除业务关联Excel", path = "/businessExcel/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated BusinessExcelBatchDelRequest businessExcelBatchDelRequest) {
        businessExcelService.batchDelete(businessExcelBatchDelRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑业务关联Excel", path = "/businessExcel/edit")
    public ResponseData<?> edit(@RequestBody @Validated BusinessExcelEditRequest businessExcelEditRequest) {
        businessExcelService.edit(businessExcelEditRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看业务关联Excel详情", path = "/businessExcel/detail")
    public ResponseData<BusinessExcelDetailResponse> detail(@Validated BusinessExcelDetailRequest businessExcelDetailRequest) {
        return new SuccessResponseData<>(businessExcelService.detail(businessExcelDetailRequest));
    }

    @GetResource(name = "获取业务关联Excel列表", path = "/businessExcel/list")
    public ResponseData<List<BusinessExcelListResponse>> list(@Validated BusinessExcelListRequest businessExcelListRequest) {
        return new SuccessResponseData<>(businessExcelService.findList(businessExcelListRequest));
    }

    @PostResource(name = "修改激活状态", path = "/businessExcel/updateStatus")
    public ResponseData<?> updateStatus(@RequestBody @Validated BusinessExcelUpdateStatusRequest businessExcelUpdateStatusRequest) {
        businessExcelService.updateStatus(businessExcelUpdateStatusRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "保存Excel", path = "/businessExcel/updateExcelContent")
    public ResponseData<?> updateExcelContent(@RequestPart("file") MultipartFile file, @Validated ExcelContentUpdateRequest excelContentUpdateRequest) {
        businessExcelService.updateExcelContent(file, excelContentUpdateRequest);
        return new SuccessResponseData<>();
    }

}