package cn.ysk.cashier.controller.shop;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.dto.shop.TbShopVideoQueryCriteria;
import cn.ysk.cashier.pojo.shop.TbShopVideo;
import cn.ysk.cashier.service.shop.TbShopVideoService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;


/**
 * @author ww
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "商户视频号/公众号管理")
@RequestMapping("/api/tbShopSource")
public class TbShopVideoController {

    private final TbShopVideoService tbShopVideoService;

    @GetMapping
    @ApiOperation("查询商户视频号")
    public ResponseEntity<Object> queryTbShopVideo(TbShopVideoQueryCriteria criteria){
        criteria.setType(3);
        return new ResponseEntity<>(tbShopVideoService.queryAllPage(criteria), HttpStatus.OK);
    }


    @GetMapping("/{id}")
    @ApiOperation("查询商户视频号")
    public Object queryInfo(@PathVariable("id") Integer id){
        return tbShopVideoService.findById(id);
    }


    @GetMapping("media")
    @ApiOperation("查询公众号")
    public ResponseEntity<Object> queryMediaPlatform(TbShopVideoQueryCriteria criteria){
        criteria.setType(1);
        return new ResponseEntity<>(tbShopVideoService.queryAllPage(criteria), HttpStatus.OK);
    }

    @PostMapping("media")
    @Log("新增公众号:#resources.name")
    @ApiOperation("新增公众号")
    public ResponseEntity<Object> createMediaPlatform(@Validated @RequestBody TbShopVideo resources){
        resources.setType(1);
        return new ResponseEntity<>(tbShopVideoService.create(resources),HttpStatus.CREATED);
    }

    @PostMapping
    @Log("新增商户视频号:#resources.name")
    @ApiOperation("新增商户视频号")
    public ResponseEntity<Object> createTbShopVideo(@Validated @RequestBody TbShopVideo resources){
        resources.setType(3);
        return new ResponseEntity<>(tbShopVideoService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改商户视频号:#resources.name")
    @ApiOperation("修改商户视频号/公众号管理")
    public ResponseEntity<Object> updateTbShopVideo(@Validated @RequestBody TbShopVideo resources){
        tbShopVideoService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除商户视频号/公众号管理:#ids")
    @ApiOperation("删除资源")
    public ResponseEntity<Object> deleteTbShopVideo(@RequestBody Integer[] ids) {
        tbShopVideoService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
