import type {
	Staff,
	Department,
	Term,
	Message,
	Post,
	RoleMap,
	Resource,
} from "@prisma/client";
import { SocketMsgType, RolePerms } from "./enum";
import { RowRequestSchema } from "./schema";
import { z } from "zod";
// import { MessageWithRelations, PostWithRelations, TroubleWithRelations } from "./generated";
export interface SocketMessage<T = any> {
	type: SocketMsgType;
	payload?: T;
}

export interface DataNode {
	title: any;
	key: string;
	hasChildren?: boolean;
	children?: DataNode[];
	value: string;
	data?: any;
	isLeaf?: boolean;
}

export interface JwtPayload {
	sub: string;
	username: string;
}
export type AppLocalSettings = {
	urgent?: number;
	important?: number;
	exploreTime?: Date;
};
export type StaffMeta = {
	photoUrl?: string;
	office?: string;
	email?: string;
	rank?: string;
};
export type StaffDto = Staff & {
	domain?: Department;
	department?: Department;
	meta?: StaffMeta;
};
export interface AuthDto {
	token: string;
	staff: StaffDto;
	refreshToken: string;
	perms: string[];
}
export type UserProfile = Staff & {
	permissions: RolePerms[];
	deptIds: string[];
	parentDeptIds: string[];
	domain: Department;
	department: Department;
	meta?: StaffMeta;
};

export interface DataNode {
	title: any;
	key: string;
	value: string;
	data?: any;
	order?: string;
	id?: string;
}
export interface TreeDataNode extends DataNode {
	hasChildren?: boolean;
	children?: TreeDataNode[];
	isLeaf?: boolean;
	pId?: string;
}
export interface DeptSimpleTreeNode extends TreeDataNode {
	hasStaff?: boolean;
}
export type StaffRowModel = {
	avatar: string;
	dept_name: string;
	officer_id: string;
	phone_number: string;
	showname: string;
	username: string;
};
export interface TokenPayload {
	id: string;
	phoneNumber: string;
	name: string;
}
export interface ResPerm {
	instruction?: boolean;
	createProgress?: boolean;
	requestCancel?: boolean;
	acceptCancel?: boolean;

	conclude?: boolean;
	createRisk?: boolean;
	editIndicator?: boolean;
	editMethod?: boolean;
	editOrg?: boolean;

	edit?: boolean;
	delete?: boolean;
	read?: boolean;
}

export type MessageDto = Message & {
	readed: boolean;
	receivers: Staff[];
	sender: Staff;
};
export type PostComment = {
	id: string;
	type: string;
	title: string;
	content: string;
	authorId: string;
	domainId: string;
	referenceId: string;
	resources: string[];
	createdAt: Date;
	updatedAt: Date;
	parentId: string;
	author: {
		id: string;
		showname: string;
		username: string;
		avatar: string;
	};
};

export interface BaseMetadata {
	size: number;
	filetype: string;
	filename: string;
	extension: string;
	modifiedAt: Date;
}
/**
 * 图片特有元数据接口
 */
export interface ImageMetadata {
	width: number; // 图片宽度(px)
	height: number; // 图片高度(px)
	compressedUrl?: string;
	orientation?: number; // EXIF方向信息
	space?: string; // 色彩空间 (如: RGB, CMYK)
	hasAlpha?: boolean; // 是否包含透明通道
}

/**
 * 视频特有元数据接口
 */
export interface VideoMetadata {
	width?: number;
	height?: number;
	duration?: number;
	videoCodec?: string;
	audioCodec?: string;
	coverUrl?: string;
}

/**
 * 音频特有元数据接口
 */
export interface AudioMetadata {
	duration: number; // 音频时长(秒)
	bitrate?: number; // 比特率(bps)
	sampleRate?: number; // 采样率(Hz)
	channels?: number; // 声道数
	codec?: string; // 音频编码格式
}

export type FileMetadata = ImageMetadata &
	VideoMetadata &
	AudioMetadata &
	BaseMetadata;

export type ResourceDto = Resource & {
	meta: FileMetadata;
};
export type PostDto = Post & {
	readed: boolean;
	liked: boolean;
	hated: boolean;
	readedCount: number;
	commentsCount: number;
	terms: TermDto[];
	author: StaffDto | undefined;
	receivers: StaffDto[];
	resources: ResourceDto[];
	perms?: {
		delete: boolean;
		// edit: boolean;
	};

	views: number;
	meta?: PostMeta;
};

export type TermDto = Term & {
	permissions: ResPerm;
	children: TermDto[];
	hasChildren: boolean;
};
export type DepartmentDto = Department & {
	parent: DepartmentDto;
	children: DepartmentDto[];
	hasChildren: boolean;
	staffs: StaffDto[];
	terms: TermDto[];
};
export type RoleMapDto = RoleMap & {
	staff: StaffDto;
};
export interface BaseSetting {
	appConfig?: {
		splashScreen?: string;
		devDept?: string;
		logo?: string;
	};
}
export interface PostMeta {
	signature?: string;
	ip?: string;
	tags?: string[];
}
export type RowModelResult = {
	rowData: any[];
	rowCount: number;
};
export type RowModelRequest = z.infer<typeof RowRequestSchema>;
