package com.younike.merchant;

import com.younike.system.domain.vo.CategoryVo;
import com.younike.system.domain.vo.MerchantCategoryModifyVO;
import com.younike.system.domain.vo.MerchantModifyVO;
import com.younike.system.domain.vo.MerchantSettledVO;
import com.younike.system.service.ICategoryService;
import com.younike.system.service.IMerchantCategoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.younike.common.annotation.Log;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.enums.BusinessType;
import com.younike.system.service.IMerchantService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 店铺信息Controller
 * 
 * @author elev
 * @date 2022-01-04
 */
@RestController
@RequestMapping("/system/merchant")
public class MerchantController extends BaseController
{
    @Autowired
    private IMerchantService merchantService;
    @Autowired
    private IMerchantCategoryService merchantCategoryService;
    @Autowired
    private ICategoryService categoryService;

    @Log(title = "入驻申请", businessType = BusinessType.INSERT)
    @PostMapping("settled")
    public AjaxResult settled(@RequestBody MerchantSettledVO merchantSettledVO)
    {
        return AjaxResult.success(merchantService.settled(merchantSettledVO));
    }

    @ApiOperation("查询店铺信息详情")
    @GetMapping("/merchantInfo")
    public AjaxResult merchantInfo(@RequestParam("merchantId") Long merchantId) {
        return AjaxResult.success(merchantService.merchantInfo(merchantId));
    }

    @Log(title = "入驻信息修改", businessType = BusinessType.UPDATE)
    @PostMapping("settledModify")
    public AjaxResult settledModify(@RequestBody MerchantSettledVO merchantSettledVO)
    {
        return AjaxResult.success(merchantService.settledModify(merchantSettledVO));
    }

    @Log(title = "商家基本信息修改", businessType = BusinessType.UPDATE)
    @PostMapping("merchantModify")
    public AjaxResult merchantModify(@RequestBody @Validated MerchantModifyVO merchantModifyVO)
    {
        return AjaxResult.success(merchantService.merchantModify(merchantModifyVO));
    }

    @Log(title = "商家服务类型修改", businessType = BusinessType.UPDATE)
    @PostMapping("merchantCategoryModify")
    public AjaxResult merchantCategoryModify(@RequestBody MerchantCategoryModifyVO merchantCategoryModifyVO)
    {
        return AjaxResult.success(merchantCategoryService.merchantCategoryModify(merchantCategoryModifyVO));
    }

    @GetMapping("categoryList")
    public AjaxResult categoryList(){
        Map<String, List<CategoryVo>> result = new HashMap<>();
        result.put("serviceList", categoryService.categoryList(1));
        result.put("repairList", categoryService.categoryList(2));
        return AjaxResult.success(result);
    }

    @GetMapping("merchantCategoryList")
    public AjaxResult merchantCategoryList(@RequestParam("merchantId") Long merchantId)
    {
        return AjaxResult.success(merchantCategoryService.merchantCategoryList(merchantId));
    }

}
