import type { Material,
	      Post,
	      TagWithSections,
	      Theatre,
	      TheatreComment,
	      TheatreInfo,
	      TheatrePostSelectionWeights,
	      TheatreProgramme,
	      User,
	      WikiPage } from '@/types'

export const buildTag = (overrides: Partial<TagWithSections> = {}): TagWithSections => ({
  id:             1,
  name:           'テストタグ',
  category:       'general',
  deprecatedAt:   null,
  aliases:        [],
  parents:        [],
  postCount:      12,
  createdAt:      '2026-01-02T03:04:05.000Z',
  updatedAt:      '2026-01-03T03:04:05.000Z',
  hasWiki:        false,
  materialId:     null,
  hasDeerjikists: false,
  matchedAlias:   null,
  sections:       [],
  children:       [],
  ...overrides,
})

export const buildPost = (overrides: Partial<Post> = {}): Post => ({
  id:                    1,
  versionNo:             1,
  url:                   'https://example.com/post/1',
  title:                 'テスト投稿',
  thumbnail:             'https://example.com/thumb.jpg',
  thumbnailBase:         null,
  videoMs:               null,
  tags:                  [buildTag ()],
  parentPosts:           [],
  childPosts:            [],
  siblingPosts:          {},
  viewed:                false,
  related:               [],
  originalCreatedFrom:   null,
  originalCreatedBefore: null,
  createdAt:             '2026-01-02T03:04:05.000Z',
  updatedAt:             '2026-01-03T03:04:05.000Z',
  uploadedUser:          { id: 1, name: 'tester' },
  ...overrides,
})

export const buildUser = (overrides: Partial<User> = {}): User => ({
  id:              1,
  name:            'tester',
  inheritanceCode: 'inherit-code',
  role:            'member',
  ...overrides,
})

export const buildWikiPage = (overrides: Partial<WikiPage> = {}): WikiPage => ({
  id:            1,
  title:         'テストWiki',
  deprecatedAt:  null,
  createdUserId: 1,
  updatedUserId: 1,
  createdAt:     '2026-01-02T03:04:05.000Z',
  updatedAt:     '2026-01-03T03:04:05.000Z',
  body:          '# 本文',
  revisionId:    10,
  pred:          null,
  succ:          null,
  ...overrides,
})

export const buildMaterial = (overrides: Partial<Material> = {}): Material => ({
  id:                    1,
  versionNo:             1,
  tag:                   buildTag (),
  file:                  null,
  url:                   null,
  sourceKind:            null,
  sourceUri:             null,
  sourcePath:            null,
  sourceFileId:          null,
  normalizedSourceKey:   null,
  wikiPageBody:          null,
  thumbnail:             null,
  thumbnailFallbackText: 'テストタグ',
  thumbnailFallbackKind: 'tag_name',
  mediaKind:             'url_only',
  contentType:           null,
  fileByteSize:          null,
  exportPaths:           {},
  exportItems:           [],
  createdAt:             '2026-01-02T03:04:05.000Z',
  createdByUser:         { id: 1, name: 'creator' },
  updatedAt:             '2026-01-03T03:04:05.000Z',
  updatedByUser:         { id: 2, name: 'updater' },
  ...overrides,
})

export const buildTheatre = (overrides: Partial<Theatre> = {}): Theatre => ({
  id:            1,
  name:          'テスト劇場',
  opensAt:       '2026-01-02T03:04:05.000Z',
  closesAt:      null,
  createdByUser: { id: 1, name: 'creator' },
  createdAt:     '2026-01-02T03:04:05.000Z',
  updatedAt:     '2026-01-03T03:04:05.000Z',
  ...overrides,
})

export const buildTheatreInfo = (
    overrides: Partial<TheatreInfo> = {},
): TheatreInfo => ({
  hostFlg:       false,
  postId:        null,
  postStartedAt: null,
  postElapsedMs: null,
  watchingUsers: [],
  skipVote:      {
    votesCount:         0,
    requiredCount:      1,
    watchingUsersCount: 0,
    voted:              false,
  },
  ...overrides,
})

export const buildTheatreComment = (
    overrides: Partial<TheatreComment> = {},
): TheatreComment => ({
  theatreId: 1,
  no:        1,
  deleted:   false,
  user:      { id: 1, name: 'tester' },
  content:   'テストコメント',
  createdAt: '2026-01-02T03:04:05.000Z',
  ...overrides,
} as TheatreComment)

export const buildTheatreProgramme = (
    overrides: Partial<TheatreProgramme> = {},
): TheatreProgramme => ({
  theatreId: 1,
  position:  1,
  post:      buildPost (),
  createdAt: '2026-01-02T03:04:05.000Z',
  ...overrides,
})

export const buildTheatrePostSelectionWeights = (
    overrides: Partial<TheatrePostSelectionWeights> = {},
): TheatrePostSelectionWeights => ({
  tagPenalties:  [],
  lightestPosts: [],
  heaviestPosts: [],
  ...overrides,
})
