package com.younike.store.controller;


import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.younike.service.pojo.vo.StoreVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import com.younike.common.core.page.PageParam;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.younike.common.annotation.OpLog;
import com.younike.common.core.controller.BaseController;
import com.younike.common.constant.BusinessType;
import com.younike.service.pojo.Store;
import com.younike.service.service.IStoreService;

/**
 * 门店基础信息Controller
 *
 * @author dail
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/store")
public class StoreController extends BaseController {
    @Autowired
    private IStoreService storeService;

    /**
     * 查询门店基础信息列表
     */
    @RequiresPermissions("store:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<Store> page) {

        return storeService.page(page);
    }


    /**
     * 获取门店基础信息详细信息
     */
    @RequiresPermissions("store:query")
    @GetMapping(value = "/{storeId}")
    public APIResult getInfo(@PathVariable("storeId") String storeId) {
        return ResultGenerator.getSuccessResult(storeService.getById(storeId));
    }

    /**
     * 新增门店基础信息
     */
//    @RequiresPermissions("store:add")
//    @OpLog(title = "门店基础信息", type = BusinessType.INSERT)
//    @PostMapping
//    public APIResult add(@RequestBody Store store) {
//        return ResultGenerator.getSuccessResult(storeService.save(store));
//    }

    /**
     * 商家端创建门店
     */
    @RequiresPermissions("store:add")
    @OpLog(title = "创建门店", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody StoreVo store) {
        return ResultGenerator.getSuccessResult(storeService.add(store));
    }


    /**
     * 修改门店基础信息
     */
    @RequiresPermissions("store:edit")
    @OpLog(title = "门店基础信息", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody Store store) {
        return ResultGenerator.getSuccessResult(storeService.updateById(store));
    }

    /**
     * 删除门店基础信息
     */
    @RequiresPermissions("store:remove")
    @OpLog(title = "门店基础信息", type = BusinessType.DELETE)
    @DeleteMapping("/{storeIds}")
    public APIResult remove(@PathVariable List<String> storeIds) {
        return ResultGenerator.getSuccessResult(storeService.removeByIds(storeIds));
    }
}
