import { UpdateActivityParam } from '@domain/backEndField/params';
import { Controller } from 'egg';

export default class ActivityController extends Controller {

    public async getActivityList() {
        const { ctx } = this;
        const { page, pageSize, form: {groupId, current, activityId, type}, sortField, sortOrder } = ctx.request.body;
        ctx.body = await ctx.service.activity.getActivityList(page, pageSize, sortField, sortOrder, type, groupId, current, activityId);
        return
    }

    public async getAllActivities() {
        const { ctx } = this;
        ctx.body = await ctx.service.activity.getAllActivities();
    }

    public async getActivityGroupList() {
        const { ctx } = this;
        console.log('******', ctx.request.body);
        const { page, pageSize, form: { serverId, current, groupId} = { serverId: 0, current: false, groupId: 0 } } = ctx.request.body;
        ctx.body = await ctx.service.activity.getActivityGroupList(page, pageSize, serverId, current, groupId);
        return
    }

    public async getAllActivityGroups() {
        const { ctx } = this;
        ctx.body = await ctx.service.activity.getAllActivityGroups();
    }

    public async getActivityGroupTypeList() {
        const { ctx } = this;
        const { page, pageSize, sortField, sortOrder, form: {groupType, groupTypeName} } = ctx.request.body;
        ctx.body = await ctx.service.activity.getActivityGroupTypeList(page, pageSize, sortField, sortOrder, groupType, groupTypeName);
        return
    }

    public async getAllActivityGroupTypes() {
        const { ctx } = this;
        ctx.body = await ctx.service.activity.getAllActivityGroupTypes();
    }

    public async updateActivityGroupType() {
        const { ctx } = this;
        const { groupType, groupTypeName, activityTypes } = ctx.request.body;
        ctx.body = await ctx.service.activity.updateActivityGroupType(groupType, groupTypeName, activityTypes);
        return
    }

    public async deleteActivityGroupType() {
        const { ctx } = this;
        const { groupType } = ctx.request.body;
        ctx.body = await ctx.service.activity.deleteActivityGroupType(groupType);
        return
    }

    public async createDefaultActivityGroupType() {
        const { ctx } = this;
        ctx.body = await ctx.service.activity.createDefaultActivityGroupType();
        return
    }

    public async createGroup() {
        const { ctx } = this;
        ctx.body = await ctx.service.activity.createGroup();
        return
    }

    public async deleteGroup() {
        const { ctx } = this;
        const { groupId } = ctx.request.body;
        ctx.body = await ctx.service.activity.deleteGroup(groupId);
        return
    }
    
    public async getActivityTaskPoint() {
        const { ctx } = this;
        const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
        ctx.body = await ctx.service.activity.getActivityTaskPoint(page, pageSize, sortField, sortOrder, form);
        return
    }

    public async createTaskToActivity() {
        const { ctx } = this;
        const { taskType, activityId } = ctx.request.body;
        ctx.body = await ctx.service.activity.createTaskToActivity(taskType, activityId);
        return
    }

    public async updateActivityTaskPoint() {
        const { ctx } = this;
        const { type, taskId, activityId, point, taskType, activityType } = ctx.request.body;
        ctx.body = await ctx.service.activity.updateActivityTaskPoint(type, taskId, activityId, activityType, taskType, point);
        return
    }

    public async delActivityTaskPoint() {
        const { ctx } = this;
        const { taskType, taskId, activityId } = ctx.request.body;
        ctx.body = await ctx.service.activity.delActivityTaskPoint(taskType, taskId, activityId);
        return
    }
    
    public async updateActivity() {
        const { ctx } = this;
        const obj = ctx.request.body;
        let param = new UpdateActivityParam(obj);
        ctx.body = await ctx.service.activity.updateActivity(param);
        return
    }

    public async switchActivity() {
        const { ctx } = this;
        const { activityId, isEnable } = ctx.request.body;
        ctx.body = await ctx.service.activity.switchActivity(activityId, isEnable);
        return
    }

    public async deleteActivity() {
        const { ctx } = this;
        const { activityId } = ctx.request.body;
        ctx.body = await ctx.service.activity.deleteActivity(activityId);
        return
    }

    public async updateActivityGroup() {
        const { ctx } = this;
        const { groupId, groupName, serverIds, activityIds, groupType } = ctx.request.body;
        ctx.body = await ctx.service.activity.updateActivityGroup(groupId, groupName, serverIds, activityIds, groupType);
        return
    }
}
