scalar DateTime
scalar JSON
scalar Upload

enum UserRole {
  ADMIN
  MODERATOR
  USER
  GUEST
}

enum ContentStatus {
  DRAFT
  PUBLISHED
  ARCHIVED
  DELETED
}

enum NotificationPriority {
  LOW
  MEDIUM
  HIGH
  URGENT
}

enum MediaType {
  IMAGE
  VIDEO
  AUDIO
  DOCUMENT
}

interface Node {
  id: ID!
  createdAt: DateTime!
  updatedAt: DateTime!
}

interface Content {
  id: ID!
  title: String!
  status: ContentStatus!
  author: User!
  metadata: JSON
}

type User implements Node {
  id: ID!
  createdAt: DateTime!
  updatedAt: DateTime!
  username: String!
  email: String!
  role: UserRole!
  profile: UserProfile
  posts: [Post!]!
  comments: [Comment!]!
  notifications: [Notification!]!
  preferences: UserPreferences!
}

type UserProfile {
  firstName: String
  lastName: String
  bio: String
  avatar: Media
  socialLinks: [SocialLink!]!
  location: Location
}

type Location {
  country: String!
  city: String
  coordinates: Coordinates
}

type Coordinates {
  latitude: Float!
  longitude: Float!
}

type SocialLink {
  platform: String!
  url: String!
  verified: Boolean!
}

type Post implements Node & Content {
  id: ID!
  createdAt: DateTime!
  updatedAt: DateTime!
  title: String!
  content: String!
  status: ContentStatus!
  author: User!
  metadata: JSON
  comments: [Comment!]!
  media: [Media!]!
  tags: [Tag!]!
  analytics: PostAnalytics!
}

type Comment implements Node {
  id: ID!
  createdAt: DateTime!
  updatedAt: DateTime!
  content: String!
  author: User!
  post: Post!
  parentComment: Comment
  replies: [Comment!]!
  reactions: [Reaction!]!
}

type Media {
  id: ID!
  type: MediaType!
  url: String!
  thumbnail: String
  metadata: MediaMetadata!
  uploader: User!
}

type MediaMetadata {
  size: Int!
  format: String!
  dimensions: Dimensions
  duration: Int
}

type Dimensions {
  width: Int!
  height: Int!
}

type Tag {
  id: ID!
  name: String!
  slug: String!
  description: String
  posts: [Post!]!
}

type Reaction {
  id: ID!
  type: String!
  user: User!
  comment: Comment!
  createdAt: DateTime!
}

type Notification {
  id: ID!
  type: String!
  priority: NotificationPriority!
  message: String!
  recipient: User!
  read: Boolean!
  createdAt: DateTime!
  metadata: JSON
}

type PostAnalytics {
  views: Int!
  likes: Int!
  shares: Int!
  comments: Int!
  engagement: Float!
  demographics: Demographics!
}

type Demographics {
  ageGroups: [AgeGroup!]!
  locations: [LocationStats!]!
  devices: [DeviceStats!]!
}

type AgeGroup {
  range: String!
  percentage: Float!
}

type LocationStats {
  country: String!
  count: Int!
}

type DeviceStats {
  type: String!
  count: Int!
}

type UserPreferences {
  theme: String!
  oldTheme: String @deprecated
  language: String!
  notifications: NotificationPreferences!
  privacy: PrivacySettings!
}

type NotificationPreferences {
  email: Boolean!
  push: Boolean!
  sms: Boolean!
  frequency: String!
}

type PrivacySettings {
  profileVisibility: String!
  showEmail: Boolean!
  showLocation: Boolean!
}

input CreateUserInput {
  username: String!
  email: String!
  password: String!
  role: UserRole = USER
  profile: CreateUserProfileInput
}

input CreateUserProfileInput {
  firstName: String
  lastName: String
  bio: String
  location: CreateLocationInput
}

input CreateLocationInput {
  country: String!
  city: String
  coordinates: CreateCoordinatesInput
}

input CreateCoordinatesInput {
  latitude: Float!
  longitude: Float!
}

input CreatePostInput {
  title: String!
  content: String!
  status: ContentStatus = DRAFT
  tags: [String!]
  media: [Upload!]
}

input UpdatePostInput {
  title: String
  content: String
  status: ContentStatus
  tags: [String!]
}

input CreateCommentInput {
  content: String!
  postId: ID!
  parentCommentId: ID
}

input NotificationFilter {
  priority: NotificationPriority
  read: Boolean
  type: String
  startDate: DateTime
  endDate: DateTime
}

type Query {
  node(id: ID!): Node
  user(id: ID!): User
  post(id: ID!): Post
  postsOld(filter: [ID!]) : [Post!]! @deprecated(reason: "Use posts instead")
  posts(filter: PostFilter): [Post!]!
  comments(postId: ID!): [Comment!]!
  notifications(filter: NotificationFilter): [Notification!]!
  subNotifications(filter: NotificationFilter): [[Notification!]!]!
  search(query: String!): SearchResult!
}

type Mutation {
  createUser(input: CreateUserInput!): User!
  createPost(input: CreatePostInput!): Post!
  updatePost(id: ID!, input: UpdatePostInput!): Post!
  createComment(input: CreateCommentInput!): Comment!
  deletePost(id: ID!): Boolean!
  uploadMedia(file: Upload!): Media!
  updateUserPreferences(id: ID!, preferences: UserPreferencesInput!): UserPreferences!
}

type Subscription {
  postUpdated(id: ID!): Post!
  newComment(postId: ID!): Comment!
  notificationReceived(userId: ID!): Notification!
}

union SearchResult = User | Post | Comment | Tag

input PostFilter {
  status: ContentStatus
  authorId: ID
  tags: [String!]
  dateRange: DateRangeInput
}

input DateRangeInput {
  start: DateTime!
  end: DateTime!
}

input UserPreferencesInput {
  theme: String
  language: String
  notifications: NotificationPreferencesInput
  privacy: PrivacySettingsInput
}

input NotificationPreferencesInput {
  email: Boolean
  push: Boolean
  sms: Boolean
  frequency: String
}

input PrivacySettingsInput {
  profileVisibility: String
  showEmail: Boolean
  showLocation: Boolean
}

directive @auth(requires: UserRole!) on FIELD_DEFINITION
directive @cache(ttl: Int!) on FIELD_DEFINITION
directive @deprecated(reason: String) on FIELD_DEFINITION 