const Setting = require("../model/Setting");
const Controller = require("./Controller");
module.exports = new class SettingController extends Controller {
    update = async (req, res, next) => {
        try {
            const ndata = req.body;
            if (!ndata) return next("data notfound");
            const object = {};
            ndata.map(group => group.feilds.map((item) => object[item.name] = item.value))
            await Setting.update("1", (data) => ({ ...data, ...object }))
            return res.success("setting update success");
        } catch (error) {
            next(error);
            return;
        }
    }
    index = async (req, res, next) => {
        try {
            const data = await Setting.find(1);

            const groupFeild = [
                {
                    label: "App Information",
                    feilds: [
                        {
                            name: "name",
                            label: "App Name",
                            value: data.name,
                            type: "text"
                        },
                        {
                            name: "fontendURL",
                            label: "Fontend URL",
                            value: data.fontendURL,
                            type: "text"
                        },
                        {
                            name: "backendURl",
                            label: "Server URL",
                            value: data.backendURl,
                            type: "text"
                        },
                        {
                            name: "notice",
                            label: "App Notice",
                            value: data.notice,
                            type: "text"
                        }
                    ]
                },
                {
                    label: "Diposit Information",
                    feilds: [
                        {
                            name: "diposit_min",
                            label: "Min Diposit",
                            value: data.diposit_min,

                            type: "number"
                        },
                        {
                            name: "diposit_max",
                            label: "Max Diposit",
                            value: data.diposit_max,
                            type: "text"
                        },
                        {
                            name: "diposit_notice",
                            label: "Diposit Notice",
                            value: data.diposit_notice,
                            type: "text"
                        },
                    ]
                },
                {
                    label: "Widthdraw Information",
                    feilds: [
                        {
                            name: "widthdrow_min",
                            label: "Min Widthdraw",
                            value: data.widthdrow_min,
                            type: "number"
                        },
                        {
                            name: "widthdrow_max",
                            label: "Max Widthdraw",
                            value: data.widthdrow_max,
                            type: "number"
                        },
                        {
                            name: "widthdrow_notice",
                            label: "Widthdraw Notice",
                            value: data.widthdrow_notice,
                            type: "text"
                        },
                    ]
                },
                // {
                //     label: "Club Information",
                //     feilds: [
                //         {
                //             name: "club_widthdrow_min",
                //             label: "Min Club Widthdraw ",
                //             value: data.club_widthdrow_min,
                //             type: "text"
                //         },
                //         {
                //             name: "club_widthdrow_max",
                //             label: "Max Club Widthdraw ",
                //             value: data.club_widthdrow_max,
                //             type: "text"
                //         }
                //     ]
                // },
                {
                    label: "Time Information",
                    feilds: [
                        {
                            name: "bettime",
                            label: "Betting Time (secoend)",
                            value: data.bettime,
                            type: "number"
                        },
                        {
                            name: "widthdrowtime",
                            label: "Widthdraw Time (hour)",
                            value: data.widthdrowtime,
                            type: "number"
                        },
                    ]
                },
                {
                    label: "Betting Information",
                    feilds: [
                        {
                            name: "maxbet",
                            label: "Max betting Amount",
                            value: data.maxbet,
                            type: "number"
                        },

                        {
                            name: "minbetret",
                            label: "Min Bet Red",
                            value: data.minbetret,
                            type: "text"
                        },
                    ]
                },
                {
                    label: "Commiton Information",
                    feilds: [
                        {
                            name: "sp_comming",
                            label: "Sponser Commition",
                            value: data.sp_comming,
                            type: "number"
                        },
                        {
                            name: "club_comming",
                            label: "Club Commiton",
                            value: data.club_comming,
                            type: "number"
                        },
                    ]
                },
                {
                    label: "Parmition Information",
                    feilds: [
                        {
                            name: "transfar_permition",
                            label: "Transfar Permition",
                            value: data.transfar_permition,
                            list: [
                                {
                                    title: "Active",
                                    value: "1"
                                },
                                {
                                    title: "Deactive",
                                    value: "0"
                                }
                            ],
                            type: "select"
                        },
                        {
                            name: "dp_parmition",
                            label: "Diposit Parmition",
                            value: data.dp_parmition,
                            list: [
                                {
                                    title: "Active",
                                    value: "active"
                                },
                                {
                                    title: "Deactive",
                                    value: "deactive"
                                }
                            ],
                            type: "select"
                        },
                        {
                            name: "wd_parmition",
                            label: "Widthdraw Parmition",
                            value: data.wd_parmition,
                            list: [
                                {
                                    title: "Active",
                                    value: "active"
                                },
                                {
                                    title: "Deactive",
                                    value: "deactive"
                                }
                            ],
                            type: "select"
                        },
                    ]
                },
            ];
            return res.success("success", groupFeild);
        } catch (error) {
            next(error);
            return;
        }
    }
}