package com.jy.business.corporation.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.business.corporation.model.dto.CorporationShopDto;
import com.jy.business.corporation.model.dto.CorporationShopSelectDto;
import com.jy.business.corporation.model.vo.CorporationShopVo;
import com.jy.business.corporation.service.CorporationShopService;
import com.jy.framework.model.annotation.RecordAudit;
import com.jy.framework.model.base.BaseSelectDto;
import com.jy.framework.model.enums.BusinessType;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商铺信息 前端控制器
 * </p>
 *
 * @author 
 * @since 2025-08-11
 */
@RestController
@RequestMapping("/corporationShop")
public class CorporationShopController {

    @Resource
    private CorporationShopService corporationShopService;

    /**
     * 商铺信息分页
     */
    @GetMapping("/getPage")
    public Page<CorporationShopVo> getPage(CorporationShopSelectDto dto) {
        return corporationShopService.getPage(dto);
    }

    /**
     * 商铺信息明细
     */
    @GetMapping("/getDetail")
    public CorporationShopVo getDetail(BaseSelectDto dto) {
        return corporationShopService.getDetail(dto.getId());
    }

    /**
     * 商铺信息新增
     */
    @RecordAudit(
            moduleName = "商铺信息-新增",
            businessType = BusinessType.INSERT
    )
    @PostMapping("/add")
    public Long add(@RequestBody CorporationShopDto dto) {
        return corporationShopService.add(dto);
    }

    /**
     * 商铺信息编辑
     */
    @RecordAudit(
            moduleName = "商铺信息-修改",
            businessType = BusinessType.UPDATE,
            getOldDataFunName = "getDetail"
    )
    @PostMapping("/edit")
    public void edit(@RequestBody CorporationShopDto dto) {
        corporationShopService.edit(dto);
    }

    /**
     * 商铺信息删除
     */
    @RecordAudit(
            moduleName = "商铺信息-删除",
            businessType = BusinessType.DELETE,
            getOldDataFunName = "getDetailList"
    )
    @PostMapping("/delete")
    public void delete(@RequestBody BaseSelectDto dto) {
        corporationShopService.delete(dto.getIdList());
    }

    public CorporationShopVo getDetail(CorporationShopDto dto) {
        return corporationShopService.getDetail(dto.getId());
    }

    public List<CorporationShopVo> getDetailList(BaseSelectDto dto) {
        return dto.getIdList().stream().map(id -> corporationShopService.getDetail(id)).toList();
    }
}
