package com.gree.mall.manager.logic.brand;

import com.gree.mall.manager.exception.RemoteServiceException;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.plus.entity.Brand;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

@Slf4j
@RestController
@Api(value = "品牌API", tags ={"品牌API"} )
@RequestMapping(value = "/brand", produces = "application/json; charset=utf-8")
public class BrandController {

    @Autowired
    BrandLogic brandLogic;

    @GetMapping("/list")
    @ApiOperation(value = "品牌-列表")
    public ResponseHelper<List<Brand>> list(
    ) throws IOException, RemoteServiceException {
        List<Brand> list = brandLogic.list();
        return ResponseHelper.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation("品牌-详情")
    public ResponseHelper<Brand> detail(
            @RequestParam String id
    ){
        Brand detail = brandLogic.detail(id);
        return ResponseHelper.success(detail);
    }

    @PostMapping("/delete")
    @ApiOperation("品牌-删除")
    public ResponseHelper delete(
            @RequestParam String id
    ){
        brandLogic.delete(id);
        return ResponseHelper.success();
    }

    @PostMapping("/save")
    @ApiOperation("品牌-保存(有id修改，没id新增)")
    public ResponseHelper save(@RequestBody Brand brand, HttpServletRequest request){
        brandLogic.save(brand,request);
        return ResponseHelper.success();
    }


    


}
