package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.LoginUserInfo;
import com.cool.store.context.PartnerUserHolder;
import com.cool.store.request.LicenseListRequest;
import com.cool.store.request.license.BusinessLicenseRequest;
import com.cool.store.request.license.FoodLicenseRequest;
import com.cool.store.response.LicenseListResponse;
import com.cool.store.response.ResponseResult;
import com.cool.store.response.SubmitLicenseResponse;
import com.cool.store.service.ApplyLicenseService;
import com.cool.store.vo.PartnerUserInfoVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/pc/license")
@Api(tags = "PC证照审核")
@Slf4j
public class PCApplyLicenseController {

    @Resource
    ApplyLicenseService applyLicenseService;

    @GetMapping(path = "/licenseList")
    @ApiOperation("证照审批列表")
    public ResponseResult<PageInfo<LicenseListResponse>> licenseList(@RequestParam(value = "pageNumber", required = true, defaultValue = "1") Integer pageNumber,
                                                                     @RequestParam(value = "pageSize", required = true, defaultValue = "10") Integer pageSize,
                                                                     @RequestParam(value = "storeName", required = false) String storeName,
                                                                     @RequestParam(value = "submitStartTime", required = false) Long submitStartTime,
                                                                     @RequestParam(value = "submitEndTime", required = false) Long submitEndTime,
                                                                     @RequestParam(value = "regionId", required = false) String regionId,
                                                                     @RequestParam(value = "status", required = false) Integer status) {
        LicenseListRequest request = new LicenseListRequest(pageNumber, pageSize, storeName, submitStartTime, submitEndTime, regionId, status);
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(applyLicenseService.licenseList(request,user));
    }

    @ApiOperation("证照办理数据回显")
    @GetMapping("/default/get")
    public ResponseResult<SubmitLicenseResponse> getDefault(@RequestParam("shopId") Long shopId) {
        return ResponseResult.success(applyLicenseService.getDefault(shopId));
    }

    /**
     * @param
     * @param status 0通过 1不通过
     * @return
     */
    @GetMapping(path = "/examine")
    @ApiOperation("证照审批")
    public ResponseResult licenseExamine(@RequestParam("id") Long shopId,
                                         @RequestParam("status") Integer status,
                                         @RequestParam("result") String result) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(applyLicenseService.licenseExamine(shopId, status, result, user));
    }


    @ApiOperation("证照办理提交-营业执照")
    @PostMapping("/submitBusinessLicense")
    public ResponseResult submitBusinessLicense(@RequestBody @Validated BusinessLicenseRequest request) {
        PartnerUserInfoVO user = PartnerUserHolder.getUser();
        return ResponseResult.success(applyLicenseService.submitBusinessLicense(request,user));
    }


    @ApiOperation("证照办理提交-食品许可证")
    @PostMapping("/submitFoodLicense")
    public ResponseResult submitFoodLicense(@RequestBody FoodLicenseRequest request) {
        PartnerUserInfoVO user = PartnerUserHolder.getUser();
        return ResponseResult.success(applyLicenseService.submitFoodLicense(request,user));
    }


}
