package com.miaxis.app.controller.record;

import com.miaxis.common.annotation.Log;
import com.miaxis.common.constant.Constants;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.domain.entity.UserInfo;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.common.utils.SecurityUtils;
import com.miaxis.customer.vo.BrowseRecordCustomerInfoVo;
import com.miaxis.record.service.IBrowseRecordInfoService;
import com.miaxis.record.vo.BrowseRecordCustomerVo;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 【浏览记录】Controller
 *
 * @author miaxis
 * @date 2021-03-23
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(Constants.STUDENT_PREFIX+"/applet/record/info")
@Api(tags={"【小程序-浏览记录】"})
public class AppletBrowseRecordInfoController extends BaseController{

    private final IBrowseRecordInfoService browseRecordInfoService;

    private final RedisTemplate redisTemplate;

    /**
     * 查询浏览记录列表
     */
    @GetMapping("/getBrowseRecordInfoList")
    @ApiOperation("查询浏览记录列表")
    public ResponsePageInfo<BrowseRecordCustomerInfoVo> getBrowseRecordInfoList(){
        //当前用户
        UserInfo userInfo = SecurityUtils.getLoginUser().getStudent();
        List<BrowseRecordCustomerInfoVo> list = browseRecordInfoService.getBrowseRecordInfoList(userInfo);
        return toResponsePageInfo(list);
    }


    /**
     * 新增浏览记录
     */
    @PutMapping(value = "/insertBrowseRecord/{id}")
    @ApiOperation("新增浏览记录")
    public Response insertBrowseRecord(
            @ApiParam(name = "id",value = "商家id",required = true)
            @PathVariable("id") Long id
    ){
        //当前用户
        UserInfo userInfo = SecurityUtils.getLoginUser().getStudent();
        return browseRecordInfoService.insertBrowseRecord(userInfo,id);
    }


    /**
     * 删除浏览记录
     */
    @Log(title = "浏览记录", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除浏览记录")
    public  Response remove(
            @ApiParam(name = "ids", value = "商家ids参数", required = true)
            @PathVariable Long[] ids
    ){
        //当前用户
        UserInfo userInfo = SecurityUtils.getLoginUser().getStudent();
        return browseRecordInfoService.removeBrowseRecord(userInfo,ids);
    }

}
