'use strict';

const Controller = require('egg').Controller;

class searchHistoryController extends Controller {

    /**
     * 获取预约列表
     */
    async getsearchHistory() {
        const { ctx } = this;
        //获取租房2和新房1的搜索记录
        let ret = {};
        let type = [1, 2];
        for (let i in type) {
            let tag = type[i] === 1 ? 'new_house' : 'rental_house';
            ret[tag] = await ctx.service.house.searchHistory.getSearchHistoryList(type[i]);
        }

        ctx.success(ret);
    }


    /**
     * 清除搜索记录
     */
    async cleanSearchHistory() {
        const { ctx } = this;
        let inputParams = ctx.params;
        const rule = {
            type: {
                type: 'string',
                required: true,
            }
        };
        ctx.validate(rule, inputParams);
        if (!['new_house', 'rental_house'].includes(inputParams.type)) {
            ctx.failed('error type');
        }
        let type = inputParams.type === 'new_house' ? 1 : 2;
        let ret = await ctx.service.house.searchHistory.cleanSearchHistory(type);
        ctx.success(ret);
    }


}

module.exports = searchHistoryController;
