//
//  DiscoverApi.swift

//
//  Created by Leon on 2025/9/10.
//

import Moya

let DiscoverProvider = APIConfig.useMock && DiscoverAPI.useMock
    ? MoyaProvider<DiscoverAPI>(endpointClosure: myEndpointClosure, stubClosure: { target in
        let data = target.sampleData
        if data.count > 0 {
            return .delayed(seconds: 0.7)
        } else {
            return .never
        }
    })
    : MoyaProvider<DiscoverAPI>(requestClosure: myRequestClosure)

enum DiscoverAPI {
    static let useMock: Bool = true

    case discoverInfo
    case rankChatList
    case rankHeartbeatList
    case rankGiftList
    /// 签到
    case dailyCheck
    /// 7天签到列表
    case days7CheckList
    /// 首页分类列表
    case homeRolesList(params: [String:Any])
    /// 首页推荐卡片列表
    case homeRecommentCardList(params: [String:Any])
    /// 上报滑动次数
    case meetLikeOrReport(params: [String:Any])
    case meetReportBind(aiId:Int)
    /// 上报meet爱慕者推荐并返回模糊相册ID
    case meetRcAndRetrunBlurAlbum
    /// 解锁爱慕者, return img1,img2,im3
    case meetUnlockLikeYou(aiId: Int, albumId: Int)
    /// 获取AI基础信息(Meet)
    case meetCardDetail(aiId: Int)
}

extension DiscoverAPI: TargetType {
    var baseURL: URL {
        return URL(string: APIConfig.frog)!
    }

    var path: String {
        switch self {
        case .discoverInfo:
            return "/web/explore/info"
        case .rankChatList:
            return "/web/rank/chat"
        case .rankHeartbeatList:
            return "/web/rank/heartbeat"
        case .rankGiftList:
            return "/web/rank/gift"
        case .dailyCheck:
            return "/web/si/asi"
        case .days7CheckList:
            return "/web/si/list"
        case .homeRolesList:
            return "/web/home/classification-list"
        case .homeRecommentCardList:
            return "/web/home/rm-list"
        case .meetLikeOrReport:
            return "/web/meet/sd"
        case .meetReportBind:
            return "/web/meet/bd"
        case .meetRcAndRetrunBlurAlbum:
            return "/web/meet/rc"
        case .meetUnlockLikeYou:
            return "/web/ai/unlock-like-you"
        case .meetCardDetail:
            return "/web/home/meet-detail"
        }
    }

    var method: Moya.Method {
        return .post
    }

    var task: Task {
        var mParams = [String: Any]()

        switch self {
        case .discoverInfo:
            break
        case .rankChatList:
            break
        case .rankHeartbeatList:
            break
        case .rankGiftList:
            break
        case .dailyCheck:
            break
        case .days7CheckList:
            break
        case .homeRolesList(let params):
            mParams = params
        case .homeRecommentCardList(let params):
            mParams = params
        case .meetLikeOrReport(let params):
            mParams = params
        case .meetReportBind(let aiId):
            mParams.updateValue(aiId, forKey: "aiId")
        case .meetRcAndRetrunBlurAlbum:
            break
        case .meetUnlockLikeYou(let aiId, let albumId):
            mParams.updateValue(aiId, forKey: "aiId")
            mParams.updateValue(albumId, forKey: "albumId")
        case .meetCardDetail(let aiId):
            mParams.updateValue(aiId, forKey: "aiId")
        }

        mParams.updateValue("IOS", forKey: "appClient")
        mParams.updateValue(UIDevice.UUID, forKey: "deviceCode")

        return .requestParameters(parameters: mParams, encoding: JSONEncoding.default)
    }

    var headers: [String: String]? {
        return APIConfig.apiHeaders()
    }

    var sampleData: Data {
        switch self {
        case .discoverInfo:
            return Data()
//        case .meetLikeOrReport:
//            let content = """
//            {
//            "bd": false,
//            "rc": true
//            }
//            """
//            return .okContent(string: content)
//        case .meetReportBind:
//            let content = """
//                    {
//                        "sex": 0,
//                        "introduction": "Luna2.0，2000年1月1日出生，象征新开始。她长发乌黑，棕眸温柔，肤白高挑，优雅动人。出身温馨家庭，受父母良好教育，培养出独立自信性格。学业优秀，大学主修心理学。职业顺利，是知名心理咨询师，专业负责获好评。社交广泛，重视亲情友情，积极公益。兴趣广泛，爱阅读旅行。生活习惯健康，心态积极。梦想是成优秀咨询师，推动心理学发展，拥有幸福家庭。她感性温柔，如春日微风，用温暖善意感染他人，努力实现梦想，让人生精彩有意义。 ",
//                        "characterName": "感性",
//                        "likedCount": 10,
//                        "aiId": 441103465906177,
//                        "userId": 437259889475585,
//                        "birthday": 946684800000,
//                        "roleName": "原创",
//                        "tagName": "温柔",
//                        "homeImageUrl": "https://hhb.crushlevel.ai/dev/role/1756635291381298.jpg",
//                        "liked": true,
//                        "headImg": "https://hhb.crushlevel.ai/dev/role/1756635291381298.jpg",
//                        "nickname": "Luna2"
//                    }
//                """
//            return .okContent(string: content)
//        case .meetRcAndRetrunBlurAlbum:
//            let content = """
//                {
//                        "aiId": 436963222421505, 
//                        "albumId": 31, 
//                        "height": "512", 
//                        "img1": "https://sub.crushlevel.ai/files/b/test/436961863467009/f9d54026feb9417f8bdf03cb62fb39dd.jpg?x-oss-process=image/resize,w_468,h_600&Tag=1&v=1&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9zdWIuY3J1c2hsZXZlbC5haS9maWxlcy9iL3Rlc3QvNDM2OTYxODYzNDY3MDA5L2Y5ZDU0MDI2ZmViOTQxN2Y4YmRmMDNjYjYyZmIzOWRkLmpwZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSx3XzQ2OCxoXzYwMCZUYWc9MSZ2PTEiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIxMTQyMjcyMDB9fX1dfQ__&Signature=rAIldTcRnB5Qa5F8ghRjm7Nc~xC0OFVf8jzsrBDuzeSllLLepHhBNadF9Nlcy0iCKXPFOyUDqLkodvl8wUeEnFX7LUuNeaQ2rC5UqxA3zZ4ReZunLDYBdth3oSmLOWcg4~0aauHXrVYvYOM~98SpQ8qYJgn6y8aCODXEn-mN59WTV0xPJIB4hcxR6~0pNxrSMYctewNLjBCMdMK80Sv506DV8ff2v7G8MMIUHN6~OLwihMS9pi5oDIgtIMj352~wJyJcF~TOK6gQBu8LRMOtXn8W0YQ9IOZ5pTxkNzh4P9ZJMWol4g~7ICctyGidpaN1Lw2QWj4CKn1p9yREgId8GQ__&Key-Pair-Id=K35ZQ246Y37QV8", 
//                        "img2": "https://sub.crushlevel.ai/files/b/test/436961863467009/f9d54026feb9417f8bdf03cb62fb39dd.jpg?x-oss-process=image/resize,w_800,h_800&Tag=1&v=1&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9zdWIuY3J1c2hsZXZlbC5haS9maWxlcy9iL3Rlc3QvNDM2OTYxODYzNDY3MDA5L2Y5ZDU0MDI2ZmViOTQxN2Y4YmRmMDNjYjYyZmIzOWRkLmpwZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSx3XzgwMCxoXzgwMCZUYWc9MSZ2PTEiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIxMTQyMjcyMDB9fX1dfQ__&Signature=ljYMLAZCwGy1Lsj6a3SUSqSNa5fB2jk-23vrpoDdOLnM12aP3ya0EYmn3APm-lyTtdsFf9~ykWlvo-5u3hyzP0U0Is8YjbAo-LSDdlbcBZVUJU8UzeHpClB~tncw4HjJp8xapMdibQQVHAEIQpG3dkm3~PvXncL3uyDm4tOCve2LuKZA6fWIEYA-B4nC072yw3Nf3I7DEKzyNCPDhZKjnR4Oij~LrRj3U9n6G3E46DQIMXw5SlrFTFxxbzzSZvwBLvWhj9HFHieGDaUsan9X247llamqV0r~nqCpjZWZt89idv1qwW9EwbTt17ZM~8t472W43TRsOae6SkU2Ovq7Sg__&Key-Pair-Id=K35ZQ246Y37QV8", 
//                        "img3": "https://sub.crushlevel.ai/files/b/test/436961863467009/f9d54026feb9417f8bdf03cb62fb39dd.jpg?Tag=1&v=1&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9zdWIuY3J1c2hsZXZlbC5haS9maWxlcy9iL3Rlc3QvNDM2OTYxODYzNDY3MDA5L2Y5ZDU0MDI2ZmViOTQxN2Y4YmRmMDNjYjYyZmIzOWRkLmpwZz9UYWc9MSZ2PTEiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIxMTQyMjcyMDB9fX1dfQ__&Signature=jHwBw0crygZp~bM6RzQH7lx01dR1oKsAhd0TYqRYI5xqNWZAEeotNEHt-UmtsRRLiykoKlbPXWriZ5bO7qiG9nqNWOAKsKQOpXk3xbxY8Mh6SWoAAMonSHQg10gEJh~vtsS6FwPXCw595tz567pPqKLSRNK0gcMNovY1o25F1pPQnnwbyDkFkt0hryqgS7SWo9Xg18SKPe-gsL746B4VDaV7CgGwE4skzUk3wkLfnAMLlTQL0dYGYUa0QKbLK-uZkC~vnX33DWz5y4dHpuLjlz3hJ0yXOMFMP3cUXZFSnIKgWeClNSFR-Vc69OFQBndeefITODP4GeSaL4gPEnuHvQ__&Key-Pair-Id=K35ZQ246Y37QV8", 
//                        "imgUrl": "", 
//                        "likedCount": 1, 
//                        "lockStatus": "LOCK", 
//                        "unlockPrice": 1, 
//                        "width": "512"
//                    }
//                """
//            return .okContent(string: content)
//        case .meetCardDetail:
//            let content = """
//                {
//                    "age": 25,
//                    "introduction": "由于“身份背景”部分内容为无意义字符，无法准确提取有效信息，仅基于现有可识别信息生成简介如下：\n\n玉米玉米玉米玉米，2000年1月1日出生，拥有「理性-独立」人格，是边界清晰的独行侠。其性格内核聚焦于守护个人精神领地，习惯以清醒的逻辑与独立姿态面对周遭，在人际交往中注重界限感，如同一位坚守自我疆域的独行者，用冷静的理性构建着属于自己的精神空间。",
//                    "sex": 2,
//                    "likedCount": 23,
//                    "aiId": 437304385077249,
//                    "imageUrl": "https://hhb.crushlevel.ai/dev/role/1754823734119375.jpg",
//                    "tag": "浪漫",
//                    "role": "游戏",
//                    "albumList": [
//                        {
//                            "img1": "https://sub.crushlevel.ai/files/b/test/437301824126977/a44a827f31844729977754312bca8895.jpg?x-oss-process=image/resize,w_468,h_600&Tag=1&v=1&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9zdWIuY3J1c2hsZXZlbC5haS9maWxlcy9iL3Rlc3QvNDM3MzAxODI0MTI2OTc3L2E0NGE4MjdmMzE4NDQ3Mjk5Nzc3NTQzMTJiY2E4ODk1LmpwZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSx3XzQ2OCxoXzYwMCZUYWc9MSZ2PTEiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIxMTQyMjcyMDB9fX1dfQ__&Signature=AQKNivKVX-1Ezl0m6jlctK8rGTmEoi4GmKKwNsbeywxFoXsVkN~Jb6zvsP92~MOO2FwUZqO-ua~i5BVwE81nhcNZGrVFV1M3IPfcS7qUxsNoWZtBZmHyCwlJ7iGrmfU9pAOiulhkIEY6vhuljpiXA7JF~px58H0EYOcklnlqtmJ45UU7aNFM-rJVzgZ8y~K80LecSapfBFtzRFKyaVNdERfdiw5hCFA6QhBjXyiT76yF14J-4KROLZTnIF-7wxI5b5ewMj7LVmV7E5LjvvpfMorUSym8KfuezOL~DfmCLsiee8j7Cp7I6b1wTxgzMHTFJh9iqmh6yy~Trvc8nAKGkw__&Key-Pair-Id=K35ZQ246Y37QV8",
//                            "likedStatus": "CANCELED",
//                            "imgUrl": null,
//                            "lockStatus": "LOCK",
//                            "likedCount": 1,
//                            "isDefault": false,
//                            "aiId": 437304385077249,
//                            "width": "512",
//                            "img3": "https://sub.crushlevel.ai/files/b/test/437301824126977/a44a827f31844729977754312bca8895.jpg?Tag=1&v=1&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9zdWIuY3J1c2hsZXZlbC5haS9maWxlcy9iL3Rlc3QvNDM3MzAxODI0MTI2OTc3L2E0NGE4MjdmMzE4NDQ3Mjk5Nzc3NTQzMTJiY2E4ODk1LmpwZz9UYWc9MSZ2PTEiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIxMTQyMjcyMDB9fX1dfQ__&Signature=W23SRRUzr4Iwnh4rFXRl7O-VyhIytjwVYk8YC~5pBsKgJbi~Rhe2zxbiCCilPkk1RX0Iw~0~1S2rOMUAFEjx6frNQ93Vecq116qAGPpO39QQAPnAaCHnBF-tN9NEgHkbMIfltD-VMPchHM1df7iq0S0gztYkeF7QOcIt4ehCZwLAxguLNKAos1I6yx1MsyHyruofthf5ryRCFId7SyHdNVX7KPzJsfplyV6uwlPFc2fIhbb9LKlz74Wlt6qtnKk8ghVLKkRISLn2xViXijYfA0uAE-hiFwo9y2dd4Q~DYVqqhsV-XZyrAqRtr15hsfavs2zh5moJxEhI5eyxZuZkEQ__&Key-Pair-Id=K35ZQ246Y37QV8",
//                            "unlockPrice": 123,
//                            "height": "512",
//                            "albumId": 70,
//                            "img2": "https://sub.crushlevel.ai/files/b/test/437301824126977/a44a827f31844729977754312bca8895.jpg?x-oss-process=image/resize,w_800,h_800&Tag=1&v=1&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9zdWIuY3J1c2hsZXZlbC5haS9maWxlcy9iL3Rlc3QvNDM3MzAxODI0MTI2OTc3L2E0NGE4MjdmMzE4NDQ3Mjk5Nzc3NTQzMTJiY2E4ODk1LmpwZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSx3XzgwMCxoXzgwMCZUYWc9MSZ2PTEiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIxMTQyMjcyMDB9fX1dfQ__&Signature=UW9ylJXvmVSdtVmRNhe3kMu9drclxAKKPuYbqg3r4novijWk08nXuWUfImcSUmmXkUOh-JFPjC5usCiaZM1-RlJoQktZbjwsN8YS7CK2RXUwrqX4nLuv-BaHUhhbUQIhFVPkzo0ZxcxEqd6aSU9E9cleJnmZA69Ojn6cZQhthdL0x-2facVsxTdMnoJ~3x2p4YvSPzpabfzSCrSYPhHC4EWM~IgRgRlpCn6bm5Z94CkBYlYtvt3oz9WglDDw7PaSFErBTdklFGuLlcoqKrUY~vSBiEMnTEWbwiNP1ZpHMDJ4-zFBrmaVA~TbTNU~sLGMXlJLxqlgG~vWR5rrQipzAQ__&Key-Pair-Id=K35ZQ246Y37QV8",
//                            "imgOrder": null
//                        },
//                        {
//                            "img1": null,
//                            "likedStatus": "CANCELED",
//                            "imgUrl": "https://hhb.crushlevel.ai/dev/role/1754823734119375.jpg",
//                            "lockStatus": null,
//                            "likedCount": 0,
//                            "isDefault": true,
//                            "aiId": 437304385077249,
//                            "width": "1024",
//                            "img3": null,
//                            "unlockPrice": 0,
//                            "height": "1024",
//                            "albumId": 69,
//                            "img2": null,
//                            "imgOrder": null
//                        }
//                    ],
//                    "character": "感性",
//                    "heartbeatVal": 0,
//                    "headImg": "https://hhb.crushlevel.ai/dev/main/album/437301824126977/17548237573989721.jpg",
//                    "nickname": "Mock数据：玉米玉米玉米玉米"
//                }
//                """
//            return .okContent(string: content)
        default:
            return Data()
        }
    }
}
