{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE TupleSections              #-}

{-|

Description: Manipulate git objects.

-}

module Data.Git.Object
    (
      ObjectType(..)
    , Object(..)
    , Blob(..)
    , Tree(..)
    , Commit(..)
    , Tag(..)
    , TreeEntry(..)

    , asBlob
    , asTree
    , asCommit
    , asTag

    , buildObject
    , buildLooseObject

    , emptyTree
    , emptyTreeSha
    ) where

import Data.Git.Internal.Object

-- | Try to view an 'Object' as a 'Blob'
asBlob :: Object -> Maybe Blob
asBlob (BlobObj b) = Just b
asBlob _           = Nothing

-- | Try to view an 'Object' as a 'Tree'
asTree :: Object -> Maybe Tree
asTree (TreeObj t) = Just t
asTree _           = Nothing

-- | Try to view an 'Object' as a 'Commit'
asCommit :: Object -> Maybe Commit
asCommit (CommitObj c) = Just c
asCommit _             = Nothing

-- | Try to view an 'Object' as a 'Tag'
asTag :: Object -> Maybe Tag
asTag (TagObj t) = Just t
asTag _          = Nothing

{-
-- | The type of an 'Object'.
objectType :: Object -> ObjectType
objectType BlobObj   {} = BlobType
objectType TreeObj   {} = TreeType
objectType CommitObj {} = CommitType
objectType TagObj    {} = TagType
-}