package com.org.hktshop.controller.encapsulation;

import com.org.hktshop.base.BaseResult;
import com.org.hktshop.entity.Page;
import com.org.hktshop.entity.encapsulation.FcBrand;
import com.org.hktshop.service.encapsulation.FcBrandService;
import com.org.hktshop.utils.HttpCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/fcBrand")
@Api(tags = "品牌接口")
public class FcBrandController {

    @Autowired
    private FcBrandService fcBrandService;

    @PostMapping("/save")
    @ApiOperation(value = "新增品牌", notes = "新增品牌")
    public BaseResult insert(@RequestBody FcBrand fcBrand) {
        try {
            fcBrandService.saveFcBrand(fcBrand);
            return BaseResult.success();
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(), HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @GetMapping("/deleteById")
    @ApiOperation(value = "删除品牌", notes = "删除品牌")
    public BaseResult deleteById(@RequestParam String id) {
        try {
            fcBrandService.deleteFcBrand(id);
            return BaseResult.success();
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(), HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改品牌", notes = "修改品牌")
    public BaseResult update(@RequestBody FcBrand fcBrand) {
        try {
            fcBrandService.updateFcBrand(fcBrand);
            return BaseResult.success();
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(), HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @GetMapping("/getById")
    @ApiOperation(value = "品牌 id查", notes = "品牌 id查")
    public BaseResult<FcBrand> getById(@RequestParam String id) {
        try {
            return BaseResult.successWithData(fcBrandService.getFcBrand(id));
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(), HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @PostMapping("/findPage")
    @ApiOperation(value = "品牌 分页查", notes = "品牌 分页查")
    public BaseResult<Page<FcBrand>> findPage(@RequestBody FcBrand fcBrand) {
        try {
            return BaseResult.successWithData(fcBrandService.getFcBrandPage(fcBrand));
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(), HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }
}
