import { FormGroup } from '@angular/forms';
import { MatDialogRef } from '@angular/material/dialog';
import { Action } from "@ngrx/store";
import { Login } from "../model/login.model";
import { LoginDialogComponent } from '../login/login-dialog/login-dialog.component';
import { User } from '../../core/model/user.model';

export const REQUEST_TOKEN = 'REQUEST_TOKEN';
export const SET_TOKEN = 'SET_TOKEN';
export const SIGN_OFF = 'SIGN_OFF';
export const SIMPLE_SIGN_OFF = 'SIMPLE_SIGN_OFF';

export const REQUEST_USER = 'REQUEST_USER';
export const SET_USER = 'SET_USER';

export const INIT_LOGIN_DIALOG = 'INIT_LOGIN_DIALOG';
export const CLOSE_LOGIN_DIALOG = 'CLOSE_LOGIN_DIALOG';

export const SET_LOGIN_TIMEOUT = 'SET_LOGIN_TIMEOUT';
export const REMOVE_LOGIN_TIMEOUT = 'REMOVE_LOGIN_TIMEOUT';

export const REQUEST_REGISTRATION = 'REQUEST_REGISTRATION';

export const REQUEST_USERS = 'REQUEST_USERS';
export const SET_USERS = 'SET_USERS';

export const REQUEST_DELETE_USER = 'REQUEST_DELETE_USER';
export const REQUEST_DELETE_OTHER_USER = 'REQUEST_DELETE_OTHER_USER';

export const REQUEST_UPDATE_USER = 'REQUEST_UPDATE_USER';
export const REQUEST_UPDATE_OTHER_USER = 'REQUEST_UPDATE_OTHER_USER';

export const REQUEST_APPROVE_USERS = 'REQUEST_APPROVE_USERS';
export const REQUEST_REJECT_USERS = 'REQUEST_REJECT_USERS';

export class RequestTokenAction implements Action{
    readonly type = REQUEST_TOKEN;
    constructor(public payload: Login){ }
}
export class SetTokenAction implements Action{
    readonly type = SET_TOKEN;
    constructor(public payload: string){ }
}
export class SignOffAction implements Action{
    readonly type = SIGN_OFF;
}
export class SimpleSignOffAction implements Action{
    readonly type = SIMPLE_SIGN_OFF;
}

export class RequestUserAction implements Action{
    readonly type = REQUEST_USER;
}
export class SetUserAction implements Action{
    readonly type = SET_USER;
    constructor(public payload: User){ }
}

export class InitLoginDialogAction implements Action{
    readonly type = INIT_LOGIN_DIALOG;
    constructor(public loginDialogReference: MatDialogRef<LoginDialogComponent>){ }
}
export class CloseLoginDialogAction implements Action{
    readonly type = CLOSE_LOGIN_DIALOG;
}

export class SetLoginTimeoutAction implements Action{
    readonly type = SET_LOGIN_TIMEOUT;
    constructor(public loginTimeout: any){ }
}
export class RemoveLoginTimeoutAction implements Action{
    readonly type = REMOVE_LOGIN_TIMEOUT;
    constructor(){ }
}

export class RequestRegistrationAction implements Action{
    readonly type = REQUEST_REGISTRATION;
    constructor(public registrationForm: FormGroup){ }
}

export class RequestUsersAction implements Action{
    readonly type = REQUEST_USERS;
}

export class SetUsersAction implements Action{
    readonly type = SET_USERS;
    constructor(public users: User[]){ }
}

export class RequestDeleteUserAction implements Action{
    readonly type = REQUEST_DELETE_USER;
}
export class RequestDeleteOtherUserAction implements Action{
    readonly type = REQUEST_DELETE_OTHER_USER;
    constructor(public id: number) {}
}

export class RequestUpdateUserAction implements Action{
    readonly type = REQUEST_UPDATE_USER;
    constructor(public profileForm: FormGroup){ }
}
export class RequestUpdateOtherUserAction implements Action{
    readonly type = REQUEST_UPDATE_OTHER_USER;
    constructor(public profileForm: FormGroup){ }
}

export class RequestApproveUsersAction implements Action{
    readonly type = REQUEST_APPROVE_USERS;
    constructor(public users: User[]){ }
}

export class RequestRejectUsersAction implements Action{
    readonly type = REQUEST_REJECT_USERS;
    constructor(public users: User[]){ }
}


export type AuthActions = RequestTokenAction | 
    SetTokenAction | 
    SignOffAction | 
    SimpleSignOffAction |
    RequestUserAction | 
    SetUserAction | 
    InitLoginDialogAction | 
    CloseLoginDialogAction | 
    SetLoginTimeoutAction |
    RemoveLoginTimeoutAction |
    RequestRegistrationAction |
    RequestUsersAction |
    SetUsersAction |
    RequestDeleteUserAction |
    RequestDeleteOtherUserAction |
    RequestUpdateUserAction |
    RequestUpdateOtherUserAction |
    RequestApproveUsersAction |
    RequestRejectUsersAction;