module AutoGUI.Discard where

import CPython.Simple.Instances
import qualified CPython.Types.Tuple as Py (fromTuple, toTuple)
import qualified CPython.Types.Unicode as Py
import Data.Typeable
import qualified Data.Text as T

-- TODO: Cpython.Simple should export the stuff from CPython.Simple.Instances

-- TODO toPy Bool
instance ToPy Bool where
  toPy :: Bool -> IO SomeObject
toPy Bool
b = [Char] -> IO SomeObject
forall a. HasCallStack => [Char] -> a
error [Char]
"nope"

-- TODO fromPy Bool
instance FromPy Bool where
  fromPy :: SomeObject -> IO Bool
fromPy SomeObject
_ = Bool -> IO Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False

-- TODO FilePath
-- instance {-# OVERLAPS #-} ToPy String where
  -- toPy = easyToPy Py.toUnicode . T.pack

-- TODO: fromPy (a, b, c, d)
instance (FromPy a, FromPy b, FromPy c, FromPy d) => FromPy (a, b, c, d) where
  fromPy :: SomeObject -> IO (a, b, c, d)
fromPy SomeObject
val = do
    [SomeObject
pyA, SomeObject
pyB, SomeObject
pyC, SomeObject
pyD] <- (Tuple -> IO [SomeObject])
-> Proxy [SomeObject] -> SomeObject -> IO [SomeObject]
forall b c.
(Concrete b, Typeable c) =>
(b -> IO c) -> Proxy c -> SomeObject -> IO c
easyFromPy Tuple -> IO [SomeObject]
Py.fromTuple Proxy [SomeObject]
forall k (t :: k). Proxy t
Proxy SomeObject
val
    a
a <- SomeObject -> IO a
forall a. FromPy a => SomeObject -> IO a
fromPy SomeObject
pyA
    b
b <- SomeObject -> IO b
forall a. FromPy a => SomeObject -> IO a
fromPy SomeObject
pyB
    c
c <- SomeObject -> IO c
forall a. FromPy a => SomeObject -> IO a
fromPy SomeObject
pyC
    d
d <- SomeObject -> IO d
forall a. FromPy a => SomeObject -> IO a
fromPy SomeObject
pyD
    (a, b, c, d) -> IO (a, b, c, d)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a
a, b
b, c
c, d
d)

instance (ToPy a, ToPy b, ToPy c) => ToPy (a, b, c) where
  toPy :: (a, b, c) -> IO SomeObject
toPy (a
a, b
b, c
c) = do
    SomeObject
pyA <- a -> IO SomeObject
forall a. ToPy a => a -> IO SomeObject
toPy a
a
    SomeObject
pyB <- b -> IO SomeObject
forall a. ToPy a => a -> IO SomeObject
toPy b
b
    SomeObject
pyC <- c -> IO SomeObject
forall a. ToPy a => a -> IO SomeObject
toPy c
c
    ([SomeObject] -> IO Tuple) -> [SomeObject] -> IO SomeObject
forall c a. Object c => (a -> IO c) -> a -> IO SomeObject
easyToPy [SomeObject] -> IO Tuple
Py.toTuple [SomeObject
pyA, SomeObject
pyB, SomeObject
pyC]