package com.movie.api.controller;
//import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageInfo;
//import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageInfo;
import com.movie.api.model.entity.Film;
import com.movie.api.service.FilmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "电影接口")
@RequestMapping("/api/film")
public class FilmController {

    @Autowired
    private FilmService filmService;

    @PostMapping("")
    @ApiOperation(value = "保存电影")
    public void save(@RequestBody Film film) {
        System.out.println("添加成功=="+film);
        filmService.save(film);
    }

    @GetMapping("")
    @ApiOperation("列出所有电影")
    public List<Film> list(String region, String type) {
        System.out.println("地区："+region+"类型 =="+type);
        if (region != null && type != null) {
            return filmService.findByRegionAndType(region, type);
        }
        return filmService.findAll();
    }

    @GetMapping("/hot/{limit}")
    @ApiOperation("获取热榜电影")
    public List<Film> listHots(@PathVariable Integer limit) {
        System.out.println("limit---"+limit);
        return filmService.findHots(limit);
    }

    @GetMapping("/name/{name}")
    @ApiOperation("搜索电影")
    public List<Film> search(@PathVariable String name) {
        return filmService.findLikeName(name);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查找电影")
    public Film findById(@PathVariable String id) {
        return filmService.findById(id);
    }

    @PutMapping("")
    @ApiOperation(value = "更新电影")
    public void update(@RequestBody Film film) {
        filmService.update(film);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除电影")
    public void deleteById(@PathVariable String id) {
        filmService.deleteById(id);
    }

//    @GetMapping("/query")
//    @ResponseBody
//    public String page(@RequestParam("currentPage")int currentPage,@RequestParam("pageSize")int pageSize){
//      PageInfo pageInfo= PageHelper.startPage(currentPage, pageSize).doSelectPageInfo(()->filmService.findAll());
//        System.out.println(pageInfo);
//        return "ok";
//    }
}
