package com.neusoft.smart.pos.advertisement.controller;


import com.neusoft.smart.pos.advertisement.service.MediaResourceService;
import com.neusoft.smart.pos.dto.advertisement.request.MediaResourceQueryRequest;
import com.neusoft.smart.pos.dto.advertisement.request.MediaResourceRequest;
import com.neusoft.smart.pos.dto.advertisement.response.MediaResourceResponse;
import com.neusoft.smart.pos.framework.bean.PaginationExtendBean;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(value = "广告资源管理restful接口", description = "广告资源管理restful接口")
@RestController
public class MediaResourceController {
	
	@Autowired
	private MediaResourceService mediaResourceService;
	
	@PostMapping("/mediaResource")
	@ApiOperation(value = "资源添加接口", notes = "资源添加接口")
	public ResponseData<MediaResourceResponse> create(@Valid @RequestBody MediaResourceRequest mediaResourceRequest,
			BindingResult bindingResult) {
		return new ResponseData<>(mediaResourceService.create(mediaResourceRequest));
	}
	
	
	@PostMapping("/mediaResources")
	@ApiOperation(value = "分页查询广告资源接口", notes = "分页查询广告资源接口")
	public ResponseData<PaginationExtendBean<MediaResourceResponse>> fetchList(@Valid @RequestBody MediaResourceQueryRequest mediaResourceQuery) {
		PaginationExtendBean<MediaResourceResponse> paginationExtendBean = new PaginationExtendBean<>();
		paginationExtendBean.setRows(mediaResourceService.getList(mediaResourceQuery));
		paginationExtendBean.setTotal(mediaResourceService.getCount(mediaResourceQuery));
		return new ResponseData<>(paginationExtendBean);
	}
	
	/**
	 * @param resourceId
	 * @return
	 */
	@DeleteMapping("/mediaResource/{resourceId}")
	@ApiOperation(value = "资源删除接口", notes = "资源删除接口")
	public ResponseData<MediaResourceResponse> create(@PathVariable Integer resourceId) {
		mediaResourceService.updateStatus(resourceId, 1);
		return new ResponseData<>();
	}
}
