import { AddReq, UserPageQuery } from '@fast-crud/fast-crud';
import { request } from '/@/utils/service';

export const apiPrefix = '/api/system/manageclass/week_schedule/';
export const apiTimetable='/api/system/manageclass/';

export function GetList(query: UserPageQuery) {
	return request({
		url: apiPrefix+'?week_offset=0',
		method: 'get',
		params: query,
	});
}
export function GetObj(id: InfoReq) {
	return request({
		url: apiPrefix + id+ '/',
		method: 'get',
	});
}

export function AddObj(obj: AddReq) {
	return request({
		url: apiTimetable,
		method: 'post',
		data: obj,
	});
}

export function UpdateObj(obj: EditReq) {
	return request({
		url: apiTimetable + obj.id + '/',
		method: 'put',
		data: obj,
	});
}

export function GetCurrentWeekList() {
	return request({
		url: apiPrefix+'?week_offset=0',
		method: 'get',
	});
}

export function getTeacherList(query: UserPageQuery){
	return request({
        url: '/api/system/app_user/?user_type=1',
        method: 'get',
		params: query,
    });
}

export function DelObj(id: number) {
	return request({
		url: apiTimetable + id + '/',
		method: 'delete',
		data: { id },
	});
}


export function GetPermission(week_offset:number) {

    return request({
        url: apiPrefix +"?week_offset="+week_offset,
        method: 'get',
    });
}

/*复制列表  */
export function CopyList(obj: AddReq) {
	return request({
		url: '/api/system/manageclass/copy-schedule/',
		method: 'post',
		data: obj,
	});
}

export async function getScheduleData(result:object): Promise<any[]> {
	const schedule = result.data.schedule;
	const timeLabels = result.data.time_labels; 
	const weekDays = ['day1', 'day2', 'day3', 'day4', 'day5', 'day6', 'day7'];

	const table: any[] = timeLabels.map((label, timeIndex) => {
		const row: any = { timeLabel: label };
		for (let day = 1; day <= 7; day++) {
		const classes = schedule[day]?.[timeIndex + 1] || [];
			row[`day${day}`] = classes;
		}
		return row;
	});
  
	return table;
  }
  

  
  