(define-module (findimagedupes)
  #:use-module (guix licenses)
  #:use-module (guix packages)
  #:use-module (guix build-system go)
  #:use-module (guix git-download)
  #:use-module (guix build utils)
  #:use-module (guix gexp)
  #:use-module (gnu packages file)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages golang)
  #:use-module (gnu packages golang-xyz)
  #:use-module (gnu packages image)
  )

(define-public go-gitlab-com-opennota-magicmime
  (package
    (name "go-gitlab-com-opennota-magicmime")
    (version "0.1.2")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                     (url "https://gitlab.com/opennota/magicmime.git")
                     (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "0qdm4xhbhspk8dnamlkcdb1zjxaq5yz3s5qzgglkgciwfmz33zwm"))))
    (build-system go-build-system)
    (arguments
      `(#:import-path "gitlab.com/opennota/magicmime"))
    (synopsis "magicmime allows you to discover a file's mimetype by looking for magic numbers in its content.")
    (description
    "magicmime is a Go package which allows you to discover a file's mimetype by looking for magic numbers in its content. It could be used as a supplementary for Go's mime package which only interprets the file extension to detect mimetypes. Internally, it implements libmagic(3) bindings.")
    (home-page "https://gitlab.com/opennota/magicmime/")
    (license asl2.0)))

(define-public go-gitlab-com-opennota-phash
  (package
    (name "go-gitlab-com-opennota-phash")
    (version "3aa12852b3a4d5040ee054aa250770d54fc0a787")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                     (url "https://gitlab.com/opennota/phash.git")
                     (commit "3aa12852b3a4d5040ee054aa250770d54fc0a787")))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "0x9glnw50y4686ghkkkqliq5v9yf499dls46mwkgr66jhnbnz4j5"))))
    (build-system go-build-system)
    (arguments
      (list #:import-path "gitlab.com/opennota/phash"
            #:phases #~(modify-phases %standard-phases
                                      (delete 'check))))
    (inputs
      (list 
        libpng
        libheif
        libjpeg-turbo
        libtiff
        gcc
    ))
    (synopsis "phash is a simple Go wrapper around the pHash library.")
    (description "phash is a simple Go wrapper around the pHash library.")
    (home-page "https://gitlab.com/opennota/phash/")
    (license gpl3)))

(define-public go-github-com-mattn-go-sqlite3-1.14.16
  (package
    (name "go-github-com-mattn-go-sqlite3")
    (version "1.14.16")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/mattn/go-sqlite3")
             (commit (string-append "v" version))))
       (file-name (git-file-name name version))
       (sha256
        (base32 "1isnmld31pqfxwrgy3a00xmcrb4zgaa1k32fbdpi9mirpkrljsgg"))))
    (build-system go-build-system)
    (arguments
     (list
      #:import-path "github.com/mattn/go-sqlite3"))
    (home-page "https://github.com/mattn/go-sqlite3")
    (synopsis "go-sqlite3")
    (description "Package sqlite3 provides interface to SQLite3 databases.")
    (license expat)))


(define-public findimagedupes
  (package
    (name "findimagedupes")
    (version "bc6c4c310f102eb04a4ac3610e2ca0ae72746bbe")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                     (url "https://gitlab.com/opennota/findimagedupes.git")
                     (commit "bc6c4c310f102eb04a4ac3610e2ca0ae72746bbe")))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "0vz45zysn4dxmlw9fjw0sjsi4wh6b98a2lczxv0rwwxjx77drya7"))))
    (build-system go-build-system)
    (arguments
      (list #:import-path "gitlab.com/opennota/findimagedupes"
            ))
    (inputs
      (list 
        libjpeg-turbo
        libpng
        libtiff
        libheif
        go-gitlab-com-opennota-magicmime
        go-gitlab-com-opennota-phash
        go-github-com-mattn-go-sqlite3-1.14.16
        ))
    (synopsis "finds visually similar or duplicate images.")
    (description "finds duplicate images using the pHash algorithm")
    (home-page "https://gitlab.com/opennota/findimagedupes/")
    (license gpl3)))