package com.hfkj.qianzhu;

import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName CinemaService
 * @Author Sum1Dream
 * @Description 电影票请求
 * @Date 2024/6/11 上午11:31
 **/
public class CinemaService {


    /**
     * @MethodName filmsPagedQuery
     * @Description: 根据城市分页查询影片
     * @param map
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/11 上午11:45
     */
    public static JSONObject filmsPagedQuery(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v1/films/pagedQuery" , map);

        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }

    }

    /**
     * @MethodName pagedQueryNotShownFilms
     * @Description:分页查询待上映影片
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/11 下午3:01
     */
    public static JSONObject pagedQueryNotShownFilms(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v1/films/pagedQueryNotShownFilms" , map);

        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }

    }

    /**
     * @MethodName cinemaBrands
     * @Description:查询所有影院品牌
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/11 下午3:21
     */
    public static JSONObject cinemaBrands() throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v1/cinema-brands/listAll" , new HashMap<>());

        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }

    }

    /**
     * @MethodName cinemasPagedQuery
     * @Description:分页查询城市影院
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/11 下午3:31
     */
    public static JSONObject cinemasPagedQuery(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v2/cinemas/pagedQuery" , map);

        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }

    }

    /**
     * @MethodName listByCinemaId
     * @Description:根据影院id查询影片
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/11 下午4:09
     */
    public static JSONObject listByCinemaId(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v1/films/listByCinemaId" , map);

        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }

    }

    /**
     * @MethodName listByCinemaAndFilm
     * @Description:根据影院和影片查询场次
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/13 下午5:48
     */
    public static JSONObject listByCinemaAndFilm(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v1/films/listByCinemaAndFilm" , map);

        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }

    }

    /**
     * @MethodName pagedQuery
     * @Description: 分页查询场次
     * @param map
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/25 上午9:58
     */
    public static JSONObject pagedQuery(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v2/shows/pagedQuery" , map);

        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }

    }

    /**
     * @MethodName getRealTimeSeatByShowId
     * @Description:查询场次实时座位
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/25 上午10:23
     */
    public static JSONObject getRealTimeSeatByShowId(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v1/shows/getRealTimeSeatByShowId" , map);

        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }

    }

    /**
     * @MethodName getByFilmsId
     * @Description:查询影片id查询影片
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/7/4 下午1:59
     */
    public static JSONObject getByFilmsId(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v1/films/getById" , map);

        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }

    }

    /**
     * @MethodName getByCinemasId
     * @Description:根据影院id查询影院
     * @param map
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/7/4 下午1:59
     */
    public static JSONObject getByCinemasId(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v1/cinemas/getById" , map);

        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }

    }

    /**
     * @MethodName createMovieOrder
     * @Description: 创建订单(备用金模式)，会直接扣除账户余额，最多只能选择 4 个座位
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/7/3 上午9:48
     */
    public static JSONObject createMovieOrder(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v5/orders/createMovieOrder" , map);

        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, object);
        }

    }

    /**
     * @MethodName getByOrderNo
     * @Description:根据订单号查询订单
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/7/4 下午5:07
     */
    public static JSONObject getByOrderNo(Map<String , Object> map) {

        try {
            JSONObject object = QianZhuService.request("/openApi/v1/orders/getByOrderNo" , map);

            if (object.getBoolean("success") && object.getInteger("code") == 10000) {
                return object;
            } else {
               return null;
            }
        } catch (Exception e) {
            return null;
        }

    }

    /**
     * @MethodName refundMovieOrder
     * @Description:订单退款接口
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/7/4 下午5:25
     */
    public static JSONObject refundMovieOrder(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v1/orders/refundMovieOrder" , map);

        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, object);
        }

    }


}
