import { DeclineSessionData, Session, SessionsFilter, SessionCommentData } from '../types/sessions';
import { apiRequest } from './helpers';

export const getUpcomingSessions = (locale: string, token: string, filter?: SessionsFilter): Promise<Session[]> => apiRequest({
    url: '/home/upcomingsessionsall',
    method: 'post',
    data: {
        sessionType: 'session',
        ...(filter || {})
    },
    locale,
    token
});

export const getRequestedSessions = (locale: string, token: string): Promise<{ requestedSessions: Session[] }> => apiRequest({
    url: '/home/coachhomedata',
    method: 'post',
    locale,
    token
});

export const getRecentSessions = (locale: string, token: string, filter?: SessionsFilter): Promise<Session[]> => apiRequest({
    url: '/home/historicalmeetings',
    method: 'post',
    data: {
        sessionType: 'session',
        ...(filter || {})
    },
    locale,
    token
});

export const getSessionDetails = (locale: string, token: string, id: number): Promise<Session> => apiRequest({
    url: '/home/session',
    method: 'post',
    data: { id },
    locale,
    token
});

export const approveRequestedSession = (locale: string, token: string, sessionId: number): Promise<any> => apiRequest({
    url: '/home/approverequestedsession',
    method: 'post',
    data: { sessionId },
    locale,
    token
});

export const declineRequestedSession = (locale: string, token: string, { sessionId, reason }: DeclineSessionData): Promise<any> => apiRequest({
    url: '/home/declinerequestedsession',
    method: 'post',
    data: {
        sessionId,
        coachDeclineReason: reason
    },
    locale,
    token
});

export const cancelUpcomingSession = (locale: string, token: string, { sessionId, reason }: DeclineSessionData): Promise<any> => apiRequest({
    url: '/home/cancelupcomingsession',
    method: 'post',
    data: {
        sessionId,
        coachCancelReason: reason
    },
    locale,
    token
});

export const addSessionComment = (locale: string, token: string, data: SessionCommentData): Promise<any> => apiRequest({
    url: '/home/session_comment',
    method: 'post',
    data,
    locale,
    token
});

export const trackingStartSession = (locale: string, token: string, id: number): Promise<any> => apiRequest({
    url: '/home/sessiontracking',
    method: 'post',
    data: { id },
    locale,
    token
});

export const finishSession = (locale: string, token: string, sessionId: number): Promise<any> => apiRequest({
    url: '/home/finishsession',
    method: 'post',
    data: { sessionId },
    locale,
    token
});
