package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.LoginUserInfo;
import com.cool.store.request.LicenseListRequest;
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.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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));
    }
}
