/*
 * Copyright (C) 2021 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

import {arrayOf, bool, number, shape, string} from 'prop-types'
import {Assignment} from './Assignment'
import {Attachment} from './Attachment'
import {Section} from './Section'
import {DiscussionPermissions} from './DiscussionPermissions'
import gql from 'graphql-tag'
import {User} from './User'
import {DiscussionEntry} from './DiscussionEntry'
import {DiscussionEntryDraft} from './DiscussionEntryDraft'
import {PageInfo} from './PageInfo'
import {ChildTopic} from './ChildTopic'
import {RootTopic} from './RootTopic'
import {GroupSet} from './GroupSet'

export const Discussion = {
  fragment: gql`
    fragment Discussion on Discussion {
      id
      _id
      title
      message
      createdAt
      updatedAt
      postedAt
      requireInitialPost
      initialPostRequiredForCurrentUser
      isSectionSpecific
      isAnnouncement
      discussionType
      allowRating
      onlyGradersCanRate
      delayedPostAt
      subscribed
      published
      canUnpublish
      lockAt
      lockedForUser
      entryCounts {
        unreadCount
        repliesCount
      }
      attachment {
        ...Attachment
      }
      assignment {
        ...Assignment
      }
      permissions {
        ...DiscussionPermissions
      }
      courseSections {
        ...Section
      }
      childTopics {
        ...ChildTopic
      }
      groupSet {
        ...GroupSet
      }
      rootTopic {
        ...RootTopic
      }
    }
    ${Attachment.fragment}
    ${Assignment.fragment}
    ${DiscussionPermissions.fragment}
    ${Section.fragment}
    ${ChildTopic.fragment}
    ${GroupSet.fragment}
    ${RootTopic.fragment}
  `,

  shape: shape({
    id: string,
    _id: string,
    title: string,
    message: string,
    createdAt: string,
    updatedAt: string,
    postedAt: string,
    requireInitialPost: bool,
    initialPostRequiredForCurrentUser: bool,
    isSectionSpecific: bool,
    isAnnouncement: bool,
    discussionType: string,
    allowRating: bool,
    onlyGradersCanRate: bool,
    delayedPostAt: string,
    lockAt: string,
    subscribed: bool,
    published: bool,
    canUnpublish: bool,
    searchEntryCount: number,
    lockedForUser: bool,
    entryCounts: shape({
      unreadCount: number,
      repliesCount: number
    }),
    author: User.shape,
    editor: User.shape,
    attachment: Attachment.shape,
    assignment: Assignment.shape,
    permissions: DiscussionPermissions.shape,
    courseSections: arrayOf(Section.shape),
    childTopics: arrayOf(ChildTopic.shape),
    groupSet: GroupSet.shape,
    rootTopic: RootTopic.shape,
    rootEntriesTotalPages: number,
    entriesTotalPages: number
  }),

  mock: ({
    id = 'RGlzY3Vzc2lvbi0x',
    _id = '1',
    title = 'X-Men Powers Discussion',
    message = 'This is a Discussion Topic Message',
    createdAt = '2020-11-23T11:40:44-07:00',
    updatedAt = '2021-04-22T12:41:56-06:00',
    postedAt = '2020-11-23T11:40:44-07:00',
    requireInitialPost = false,
    initialPostRequiredForCurrentUser = false,
    isSectionSpecific = false,
    isAnnouncement = false,
    discussionType = 'threaded',
    allowRating = true,
    onlyGradersCanRate = false,
    delayedPostAt = null,
    lockAt = null,
    subscribed = true,
    published = true,
    canUnpublish = false,
    searchEntryCount = 3,
    lockedForUser = false,
    entryCounts = {
      unreadCount: 2,
      repliesCount: 56,
      __typename: 'DiscussionEntryCounts'
    },
    author = User.mock({_id: '1', displayName: 'Charles Xavier'}),
    editor = User.mock({_id: '1', displayName: 'Charles Xavier'}),
    attachment = Attachment.mock(),
    assignment = Assignment.mock(),
    permissions = DiscussionPermissions.mock(),
    courseSections = [Section.mock()],
    childTopics = [ChildTopic.mock()],
    groupSet = GroupSet.mock(),
    rootTopic = RootTopic.mock(),
    entriesTotalPages = 2,
    discussionEntriesConnection = {
      nodes: [DiscussionEntry.mock()],
      pageInfo: PageInfo.mock(),
      __typename: 'DiscussionEntriesConnection'
    },
    discussionEntryDraftsConnection = {
      nodes: [DiscussionEntryDraft.mock()],
      pageInfo: PageInfo.mock(),
      __typename: 'DiscussionEntryDraftsConnection'
    }
  } = {}) => ({
    id,
    _id,
    title,
    message,
    createdAt,
    updatedAt,
    postedAt,
    requireInitialPost,
    initialPostRequiredForCurrentUser,
    isSectionSpecific,
    isAnnouncement,
    discussionType,
    allowRating,
    onlyGradersCanRate,
    delayedPostAt,
    lockAt,
    subscribed,
    published,
    canUnpublish,
    entryCounts,
    lockedForUser,
    author,
    editor,
    attachment,
    assignment,
    permissions,
    courseSections,
    childTopics,
    groupSet,
    rootTopic,
    searchEntryCount,
    entriesTotalPages,
    discussionEntriesConnection,
    discussionEntryDraftsConnection,
    __typename: 'Discussion'
  })
}

export const DefaultMocks = {
  Discussion: () => ({
    _id: '1',
    title: 'This is a Title'
  })
}

@@ -1690,30 +1690,33 @@
 ockAt%0A      
-locked
+available
 ForUser%0A    
@@ -2850,30 +2850,33 @@
 number,%0A    
-locked
+available
 ForUser: boo
@@ -3998,30 +3998,33 @@
 nt = 3,%0A    
-locked
+available
 ForUser = fa
@@ -4017,28 +4017,27 @@
 leForUser = 
-fals
+tru
 e,%0A    entry
@@ -5278,14 +5278,17 @@
     
-locked
+available
 ForU

Change lockedForUser to availableForUser in discussion query