import _ from "lodash";
export interface DTOModel<T extends {} | undefined> {
  status: number;
  type: string;
  message: string;
  description: string;
  data: T;
}

export interface FailureDTO {
  statusCode: number;
  message: string;
}

export interface GraphQLFailureDTO {
  errors: {code: string, message: string, name: string}[]
}

export function isDTOModel(obj: any): obj is DTOModel<any> {
  return obj !== null && typeof obj === "object" && !!obj.isDTOModel;
}

export const isDTO = (obj: any): obj is DTOModel<any> => obj.data !== null &&
_.isObject(obj.data) &&
_.has(obj.data, "status") &&
_.has(obj.data, "type") && 
_.has(obj.data, "message") && 
_.has(obj.data, "description") && 
_.has(obj.data, "data")

export const GRAPHQL_UNAUTHORIZED_KEY = "UNAUTHENTICATED";